<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>网站管理系统</title>
		<link rel="stylesheet" href="/static/js/kindeditor/themes/default/default.css" />
		<link rel="stylesheet" href="/static/admin/site.css?rand={:time()}" />
		<script src="/static/js/jquery.min.js"></script>
	</head>
	<body class="{:cookie('menu_show')?'hide-menu':''}">
		<div class="sider">
			<h1><a href="{:url('index/index')}">网站管理系统</a></h1>
			<ul>
				{volist name=":db('menu')->where('pid',0)->order('sort')->select()" id="m1"}
				<li>
					<a href="#">{$m1['name']}<i></i></a>
					<div>
						{volist name=":db('menu')->where('pid',$m1['id'])->select()" id="m2"}
						<a href="{:url($m2['url'])}" id="menu_{$m2['id']}">{$m2['name']}</a>
						{/volist}
					</div>
				</li>
				{/volist}
			</ul>
		</div>
		<div class="header ">
			<div class="clear">
				<div class=" fl">
					
					<a href="#" class="menu-btn">
                        <svg t="1601973557119" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4365" ><path d="M800 320 224 320c-17.664 0-32-14.336-32-32s14.336-32 32-32l576 0c17.696 0 32 14.336 32 32S817.696 320 800 320z" p-id="4366" fill="#707070"></path><path d="M800 544 224 544c-17.664 0-32-14.336-32-32s14.336-32 32-32l576 0c17.696 0 32 14.336 32 32S817.696 544 800 544z" p-id="4367" fill="#707070"></path><path d="M800 768 224 768c-17.664 0-32-14.336-32-32s14.336-32 32-32l576 0c17.696 0 32 14.336 32 32S817.696 768 800 768z" p-id="4368" fill="#707070"></path></svg>
                    </a>
				</div>
				<div class="fr">
					<ul class="nav clear">
						<li class="nav-index">
                            
							<a href="/" target="_blank">网站首页</a>
						</li>
                        <li>
                            <a href="{:url('index/clear')}" class="ajax">清除缓存</a>
                        </li>
						<li>
							<a href="#">{$admin['name']}<i></i></a>
							<div>
								<a href="{:url('admin/pwd')}">修改密码</a>
								<a href="{:url('index/logout')}" class="ajax">退出系统</a>
							</div>
						</li>
					</ul>
				</div>
				<h3>网站管理系统</h3>
			</div>
		</div>
		<div class="main">
			{__CONTENT__}
		</div>
		
		<form id="batch-form" method="post" style="height: 0;overflow: hidden;">
			
		</form>

		<script src="/static/js/jscolor.min.js"></script>
		<script src="/static/js/jquery.cookie.min.js"></script>
		<script src="/static/js/layer/layer.js"></script>
		<script src="/static/js/laydate/laydate.js"></script>
		<script src="/static/js/jquery.form.min.js"></script>
		<script src="/static/js/validator/jquery.validator.min.js?local=zh-CN"></script>
		<script src="/static/js/kindeditor/kindeditor-all-min.js"></script>
		<script>
			
			$(function() {
				if($(".table .batch").length>0){
					$(".table .batch").attr("colspan",$(".table thead tr th").length);
				}
				if($(".table .td-empty").length>0){
					$(".table .td-empty").attr("colspan",$(".table thead tr th").length);
				}
				
				
				$("#ck-all").change(function(){
					var obj=$(this).parent().parent().parent().parent().parent().find(".ck");
					obj.prop("checked",$(this).prop('checked'));
				})
				
				$(".batch a").click(function(e){
					e.preventDefault();
					var obj=$(this);
					var ck=$(this).parent().parent().parent().parent().parent().find(".ck:checked");
					console.log(ck);
					if(ck.length==0){
						layer.msg("请选择操作记录");
						return false;
					}
					layer.confirm('确认执行<b>'+obj.html()+"</b>操作吗", {title:'提示'}, function(index){
						layer.close(index);
						$("#batch-form").attr('action',obj.attr("href"));
						$("#batch-form").html('');
						$("#batch-form").append(ck.clone());
						$("#batch-form").ajaxSubmit({
							beforeSend: function(e) {
								layer.load(2, {
									shade: [0.1, '#000']
								});
							},
							error: function(e) {
								layer.closeAll('loading');
								layer.alert("提交失败！");
							},
							success: function(data) {
								console.log(data);
								layer.closeAll('loading');
								if (data.msg) {
									layer.msg(data.msg, {
										icon: data.code,
										shade: [0.1, '#000'],
										time: 1500
									}, function() {
										if (data.url) {
											location.href = data.url;
										}
									});
								} else if (data.url) {
									location.href = data.url;
								}
							}
						});
					 
					});
				})
				
				
				$(".input-color input[type='color']").change(function(){
					var obj=$(this);
					obj.parent().find('.input').val(obj.val());
				})
				
				$(".tab .tab-title a").click(function(e){
					e.preventDefault();
					var obj=$(this).parent().parent();
					obj.find(".tab-title a").removeClass('on');
					$(this).addClass('on');
					obj.find(".tab-body li").removeClass('on');
					obj.find(".tab-body li").eq($(this).index()).addClass('on');
				})
				
				
				$(".menu-btn").click(function(e){
					e.preventDefault();
                    if($("body").hasClass('hide-menu')){
						$('body').removeClass('hide-menu');
						$.cookie('menu_show', 0, {
							path: '/'
						});
					}else{
						$('body').addClass('hide-menu');
						$.cookie('menu_show', "1", {
							path: '/'
						});
					}
				})
				
				
				$(".sider>ul>li>a").click(function(e) {
					e.preventDefault();
					var obj = $(this).parent();
					console.log(obj.hasClass('open'));
					if (obj.hasClass('open')) {
						obj.removeClass('open');
					} else {
						$(".sider>ul>li").removeClass('open');
						obj.addClass('open');
					}
				})
				$(".sider>ul>li>div>a").click(function(e) {
					e.preventDefault();
                    
                     var sUserAgent = navigator.userAgent;
                        if (sUserAgent.indexOf('Android') > -1 || sUserAgent.indexOf('iPhone') > -1 || sUserAgent.indexOf('iPad') > -1 || sUserAgent.indexOf('iPod') > -1 || sUserAgent.indexOf('Symbian') > -1) {
                            $('body').removeClass('hide-menu');
                            $.cookie('menu_show', 0, {
                            	path: '/'
                            });
                        }
                    
					var obj = $(this);
					$(".sider>ul>li>div>a").removeClass('on');
					$.cookie('menu_id', obj.attr('id'), {
						path: '/'
					});
					location.href = $(this).attr('href');
				})
				if ($.cookie('menu_id')) {
					var obj = $("#" + $.cookie('menu_id'));
					obj.addClass('on');
					obj.parent().parent().addClass("open");
				}

				if ($('.editor').length > 0) {
					var editor = KindEditor.create($('.editor'), {
						uploadJson: "{:url('index/upload')}",
						width:'100%',
						allowFileManager: false
					});
				}
				if ($('.date').length > 0) {
					laydate.render({
					  elem: '.date'
					  ,range: true
					});
				}

				if ($('.image').length > 0) {
					
					var editor_image = KindEditor.editor({
						uploadJson: "{:url('index/upload')}",
						allowFileManager: false
					});
					$('.image').click(function() {
						var obj=$(this);
						console.log(obj);
						editor_image.loadPlugin('image', function() {
							editor_image.plugin.imageDialog({
								showRemote : false,
								imageUrl: obj.find("input").val(),
								clickFn: function(url, title, width, height, border, align) {
									console.log(url);
									obj.find("input").val(url);
									obj.find('img').attr('src',url);
									editor_image.hideDialog();
								}
							});
						});
					});
					$('.image i').click(function(e) {
						e.stopPropagation();
						var obj=$(this).parent();
						obj.find('input').val('');
						obj.find('img').attr('src','/static/admin/image.png');
					});
					
				}


				$(".form-search .form-action span").click(function(e) {
					e.preventDefault();
					var obj = $(this).parent().parent();
					if (obj.hasClass('open')) {
						obj.removeClass('open');
					} else {
						obj.addClass('open');
					}
				})

				$('.form-ajax').on('valid.form', function() {
					$(this).ajaxSubmit({
						beforeSend: function(e) {
							var sub = $('.ajax-form').find("#sub");
							sub.data("title", sub.html()).html("提交中").attr("disabled", "disabled");
							layer.load(2, {
								shade: [0.1, '#000']
							});
						},
						error: function(e) {
							layer.closeAll('loading');
							var sub = $('.ajax-form').find("#sub");
							sub.html(sub.data("title")).removeAttr("disabled", "disabled");
							layer.alert("提交失败！");
						},
						success: function(data) {
							console.log(data);
							layer.closeAll('loading');
							var sub = $('.ajax-form').find("#sub");
							sub.html(sub.data("title")).removeAttr("disabled", "disabled");
							if (data.msg) {
								layer.msg(data.msg, {
									icon: data.code,
									shade: [0.1, '#000'],
									time: 1500
								}, function() {
									if (data.url) {
										location.href = data.url;
									}
								});
							} else if (data.url) {
								location.href = data.url;
							}
						}
					});
					return false;
				});

				$(".ajax").on('click', function(e) {
					e.preventDefault();
					var obj = $(this);
					info = obj.attr('title') ? obj.attr('title') : obj.text();
					layer.confirm('确认执行' + info + "操作吗？", {
							title: '提示',
							btn: ['确定', '取消']
						},
						function(index) {
							layer.closeAll();
							layer.load(2, {
								shade: [0.1, '#000']
							});
							$.get(obj.attr('href'), function(data) {
								layer.closeAll('loading');
								if (data.msg == '') {
									location.href = data.url;
								} else {
									layer.msg(data.msg, {
										icon: data.code,
										time: 1500
									}, function() {
										if (data.url != '') {
											location.href = data.url;
										}
									});
								}
							});
						},
						function(index, layero) {
							layer.close(index);
						});
				});
				$(".prompt").on('click', function(e) {
					e.preventDefault();
					var obj = $(this);
					info = obj.attr('title') ? obj.attr('title') : obj.text();
						layer.prompt( {
							title: info
							 
						},
						function(value,index) {
							layer.closeAll();
							layer.load(2, {
								shade: [0.1, '#000']
							});
							$.post(obj.attr('href'),{value:value}, function(data) {
								console.log(data);
								layer.closeAll('loading');
								if (data.msg == '' &&  data.url ) {
									location.href = data.url;
								} else {
									layer.msg(data.msg, {
										icon: data.code,
										time: 1500
									}, function() {
										if (data.url != '') {
											location.href = data.url;
										}
									});
								}
							});
						},
						function(index, layero) {
							layer.close(index);
						});
				});
				
				
				layer.photos({
				  photos: '.photo'
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				}); 
			})
		</script>
	</body>
</html>
